#include <opencv2/opencv.hpp>
#include <iostream>
#include <ctime>
#include <string>
#include <fstream>
#include "dimp/preprocess_for_init.hpp"
#include "string.h"
#include "unistd.h"
#define N 9999

using namespace cv;
using namespace std;



cv::Mat Preprocess_for_init::sample_patch(Mat img, Vector sample_pos, Vector sample_size, Vector output_size, Box *sample_coords)
{
	struct timeval begin;
    struct timeval end;
	int img_shape_1 = img.cols;
	int img_shape_0 = img.rows;
	float resize_factor = min(sample_size.x / output_size.x, sample_size.y / output_size.y);
	int df = int(max(int(resize_factor - 0.1), 1));
	
	Vector size = { float(ceil(img_shape_1 / df)), float(ceil(img_shape_0 / df)) };
	Vector sz = { float(ceil(sample_size.x / df)), float(ceil(sample_size.y / df)) };
	Mat down_sample_img;
	// gettimeofday(&begin, NULL);
	if (df > 1)
	{
		Vector os = { float(int(sample_pos.x) % df), float(int(sample_pos.y) % df) };
		sample_pos = { (sample_pos.x - os.x) / df, (sample_pos.y - os.y) / df };
		resize(img, down_sample_img, cv::Size(int(size.x), int(size.y)));
	}
	else
	{
		down_sample_img = img;
	}
	// gettimeofday(&end, NULL);
    // float time_cost = 1000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec) / 1000.000;
    // INFO_LOG("down_sample time: %fms", time_cost);

	int down_sample_img_size_0 = down_sample_img.rows;
	int down_sample_img_size_1 = down_sample_img.cols;

	Vector img_size = { float(down_sample_img_size_0), float(down_sample_img_size_1) };
	//imshow("down_sample", down_sample_img);
	//waitKey(0);

	Vector szl = { ceil(sz.x), ceil(sz.y) };
	Vector top_left = { ceil(sample_pos.x - (szl.x - 1) / 2), ceil(sample_pos.y - (szl.y - 1) / 2) };
	Vector bottom_right = { ceil(sample_pos.x + szl.x / 2 + 1), ceil(sample_pos.y + szl.y / 2 + 1) };
	int up_padding = top_left.x > 0 ? 0 : (0 - top_left.x);
	int bottom_padding = bottom_right.x < img_size.x ? 0 : (bottom_right.x - img_size.x);
	int left_padding = top_left.y > 0 ? 0 : (0 - top_left.y);
	int right_padding = bottom_right.y < img_size.y ? 0 : (bottom_right.y - img_size.y);
	Mat padding_img;
	// gettimeofday(&begin, NULL);
	if (up_padding == 0 && bottom_padding == 0 && left_padding == 0 && right_padding == 0) {
		padding_img = down_sample_img;
	}

	else {	
		copyMakeBorder(down_sample_img, padding_img, up_padding, bottom_padding, left_padding, right_padding, cv::BORDER_REPLICATE);
	}
	// gettimeofday(&end, NULL);
    // time_cost = 1000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec) / 1000.000;
    // INFO_LOG("copymakeborder time: %fms", time_cost);

	//imshow("padding_img", padding_img);
	//waitKey(0);

	int crop_up = top_left.x > 0 ? top_left.x : 0;
	int crop_bottom = 0;

	if ((top_left.x + 0.001 > 0) && (bottom_right.x + 0.001 < img_size.x))
	{
		crop_bottom = bottom_right.x;
	}
	if ((top_left.x + 0.001 > 0) && (bottom_right.x + 0.001 > img_size.x))
	{
		crop_bottom = img_size.x + bottom_padding;
	}
	if ((top_left.x + 0.001 < 0) && (bottom_right.x + 0.001 < img_size.x))
	{
		crop_bottom = img_size.x + up_padding;
	}
	if ((top_left.x + 0.001 < 0) && (bottom_right.x + 0.001 > img_size.x))
	{
		crop_bottom = img_size.x + bottom_padding + up_padding;
	}
	int crop_left = top_left.y > 0 ? top_left.y : 0;
	int crop_right = 0;
	if ((top_left.y + 0.001 > 0) && (bottom_right.y + 0.001 < img_size.y))
	{
		crop_right = bottom_right.y;
	}
	if ((top_left.y + 0.001 > 0) && (bottom_right.y + 0.001 > img_size.y))
	{
		crop_right = img_size.y + right_padding;
	}
	if ((top_left.y + 0.001 < 0) && (bottom_right.y + 0.001 < img_size.y))
	{
		crop_right = bottom_right.y + left_padding;
	}
	if ((top_left.y + 0.001 < 0) && (bottom_right.y + 0.001 > img_size.y))
	{
		crop_right = img_size.y + right_padding + left_padding;
	}

	// gettimeofday(&begin, NULL);
	Mat crop_img = padding_img(Range(crop_up, crop_bottom), Range(crop_left, crop_right));
	// gettimeofday(&end, NULL);
    // time_cost = 1000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec) / 1000.000;
    // INFO_LOG("crop time: %fms", time_cost);

	Mat output_img;

	// gettimeofday(&begin, NULL);
	resize(crop_img, output_img, cv::Size(output_size.y, output_size.x));
	// gettimeofday(&end, NULL);
    // time_cost = 1000 * (end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec) / 1000.000;
    // INFO_LOG("resize time: %fms", time_cost);
	(*sample_coords).top_left.x = top_left.x * df;
	(*sample_coords).top_left.y = top_left.y * df;
	(*sample_coords).bottom_right.x = bottom_right.x * df;
	(*sample_coords).bottom_right.y = bottom_right.y * df;
	//imshow("crop_img", output_img);
	//waitKey(0);
	return output_img;
}

Result Preprocess_for_init::transform_image(Mat img, Target_Box init_box, vector<cv::Mat>& transform_imgs, vector<Target_Box>& transform_boxes)
{

	int crop_up = 144;
	int crop_bottom = 432;
	int crop_left = 144;
	int crop_right = 432;
	//cout << img.cols << endl;
	//cout << img.rows << endl;
	transform_imgs.push_back(img(Range(crop_up, crop_bottom), Range(crop_left, crop_right)));

	//cout << img.cols << endl;
	//cout << img.rows << endl;
	transform_boxes.push_back(init_box);
	//int temp_crop_up = (crop_up - 86);
	//int temp_crop_bottom = (crop_bottom - 86);
	//int temp_crop_left = (crop_left - 86);
	//int temp_crop_right = (crop_right - 86);
	//cout << temp_crop_up << endl;
	//cout << temp_crop_bottom << endl;
	//cout << temp_crop_left << endl;
	//cout << temp_crop_right << endl;
	transform_imgs.push_back(img(Range((crop_up - 86), (crop_bottom - 86)), Range((crop_left - 86), (crop_right - 86))));
	//cout << trans_img.shift_img_1.cols << endl;
	//cout << trans_img.shift_img_1.rows << endl;
	transform_boxes.push_back({ {init_box.pos.x + 86, init_box.pos.y + 86}, {init_box.size.x, init_box.size.y} });
	transform_imgs.push_back(img(Range(crop_up + 86, crop_bottom + 86), Range(crop_left - 86, crop_right - 86)));
	transform_boxes.push_back({ {init_box.pos.x + 86, init_box.pos.y - 86}, {init_box.size.x, init_box.size.y} });
	transform_imgs.push_back(img(Range(crop_up - 86, crop_bottom - 86), Range(crop_left + 86, crop_right + 86)));
	transform_boxes.push_back({ {init_box.pos.x - 86, init_box.pos.y + 86}, {init_box.size.x, init_box.size.y} });
	transform_imgs.push_back(img(Range(crop_up + 86, crop_bottom + 86), Range(crop_left + 86, crop_right + 86)));
	transform_boxes.push_back({ {init_box.pos.x - 86, init_box.pos.y - 86}, {init_box.size.x, init_box.size.y} });

	float shift[16];
	srand(time(NULL));
	for (int i = 0; i < 16; i++)
	{
		shift[i] = rand() % (N + 1) / float(N + 1);
		shift[i] = ceil((shift[i] - 0.5) * 288 / 3);

	}
	//imshow("img", img);
	//waitKey(0);
	Mat temp_img;
	flip(img, temp_img, 1);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[1], crop_bottom - shift[1]), Range(crop_left - shift[0], crop_right - shift[0])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[0], init_box.pos.y + shift[1]}, {init_box.size.x, init_box.size.y} });
	//imshow("flip_img", trans_img.flip_img);
	//waitKey(0);
	GaussianBlur(img, temp_img, cv::Size(1, 1), 1, 1);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[3], crop_bottom - shift[3]), Range(crop_left - shift[2], crop_right - shift[2])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[2], init_box.pos.y + shift[3]}, {init_box.size.x, init_box.size.y} });
	//imshow("temp_img", temp_img);
	//waitKey(0);
	//imshow("blur_img_1", trans_img.blur_img_1);
	//waitKey(0);

	GaussianBlur(img, temp_img, cv::Size(5, 5), 5, 5);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[5], crop_bottom - shift[5]), Range(crop_left - shift[4], crop_right - shift[4])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[4], init_box.pos.y + shift[5]}, {init_box.size.x, init_box.size.y} });

	//imshow("blur_img_2", trans_img.blur_img_2);
	//waitKey(0);

	GaussianBlur(img, temp_img, cv::Size(9, 9), 9, 9);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[7], crop_bottom - shift[7]), Range(crop_left - shift[6], crop_right - shift[6])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[6], init_box.pos.y + shift[7]}, {init_box.size.x, init_box.size.y} });

	//imshow("blur_img_3", trans_img.blur_img_3);
	//waitKey(0);

	warpAffine(img, temp_img, getRotationMatrix2D(cv::Point2f(288, 288), 10, 1), cv::Size(img.cols, img.rows), cv::BORDER_REFLECT);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[9], crop_bottom - shift[9]), Range(crop_left - shift[8], crop_right - shift[8])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[8], init_box.pos.y + shift[9]}, {init_box.size.x, init_box.size.y} });

	//imshow("rotate_img_1", trans_img.rotate_img_1);
	//waitKey(0);

	warpAffine(img, temp_img, getRotationMatrix2D(cv::Point2f(288, 288), -10, 1), cv::Size(img.cols, img.rows), cv::BORDER_REFLECT);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[11], crop_bottom - shift[11]), Range(crop_left - shift[10], crop_right - shift[10])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[10], init_box.pos.y + shift[11]}, {init_box.size.x, init_box.size.y} });

	//imshow("rotate_img_2", trans_img.rotate_img_2);
	//waitKey(0);

	warpAffine(img, temp_img, getRotationMatrix2D(cv::Point2f(288, 288), 45, 1), cv::Size(img.cols, img.rows), cv::BORDER_REFLECT);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[13], crop_bottom - shift[13]), Range(crop_left - shift[12], crop_right - shift[12])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[12], init_box.pos.y + shift[13]}, {init_box.size.x, init_box.size.y} });

	//imshow("rotate_img_3", trans_img.rotate_img_3);
	//waitKey(0);

	warpAffine(img, temp_img, getRotationMatrix2D(cv::Point2f(288, 288), -45, 1), cv::Size(img.cols, img.rows), cv::BORDER_REFLECT);
	transform_imgs.push_back(temp_img(Range(crop_up - shift[15], crop_bottom - shift[15]), Range(crop_left - shift[14], crop_right - shift[14])).clone());
	transform_boxes.push_back({ {init_box.pos.x + shift[14], init_box.pos.y + shift[15]}, {init_box.size.x, init_box.size.y} });

	//imshow("rotate_img_4", trans_img.rotate_img_4);
	//waitKey(0);

	//imshow("trans_img_flip_img", trans_img.flip_img);
	//waitKey(0);
	//imshow("trans_img_blur_img_1", trans_img.blur_img_1);
	//waitKey(0);

	return SUCCESS;
}


struct Target_Box Preprocess_for_init::get_iou_box(Vector target_pos, Vector target_size, Vector sample_pos, float sample_scale) 
{
	//cout << target_pos.x << endl;
	//cout << target_pos.y << endl;
	//cout << target_size.x << endl;
	//cout << target_size.y << endl;
	//cout << sample_scale << endl;
	Vector box_center = { (target_pos.x - sample_pos.x) / sample_scale + (288 - 1) / 2, (target_pos.y - sample_pos.y) / sample_scale + (288 - 1) / 2 };
	// cout << "box_center = "<<box_center.x << " + "<<box_center.y<<endl;
	Vector box_size = { target_size.y / sample_scale, target_size.x / sample_scale};
	Vector up_left = {box_center.y - (box_size.x - 1) / 2,  box_center.x - (box_size.y - 1) / 2};
	
	// Vector up_left = {(143 - (box_size.x - 1) / 2) , (143 - (box_size.y - 1) / 2)};
	//cout << up_left.x << endl;
	//cout << up_left.y << endl;
	//cout << box_size.x << endl;
	//cout << box_size.y << endl;
	Target_Box init_iou_box = { up_left, box_size };
	// cout << init_iou_box.pos.x << endl;
	// cout << init_iou_box.pos.y << endl;
	// cout << init_iou_box.size.x << endl;
	// cout << init_iou_box.size.y << endl;
	return init_iou_box;
}

void Preprocess_for_init::SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)
{
	std::string::size_type pos1, pos2;
	pos2 = s.find(c);
	pos1 = 0;
	while (std::string::npos != pos2)
	{
		v.push_back(s.substr(pos1, pos2 - pos1));

		pos1 = pos2 + c.size();
		pos2 = s.find(c, pos1);
	}
	if (pos1 != s.length())
		v.push_back(s.substr(pos1));
}

// int test_transform(Transform_Images transform_images, Transform_box patch_coords)
// {
// 	//cout << patch_coords.shift_img_1.pos.x << endl;
// 	//cout << patch_coords.shift_img_1.pos.y << endl;
// 	//cout << patch_coords.shift_img_1.size.x << endl;
// 	//cout << patch_coords.shift_img_1.size.y << endl;
// 	rectangle(transform_images.oringin_img, cv::Rect(patch_coords.oringin_img.pos.x, patch_coords.oringin_img.pos.y, patch_coords.oringin_img.size.x, patch_coords.oringin_img.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_origin", transform_images.oringin_img);
// 	waitKey(0);
// 	rectangle(transform_images.shift_img_1, cv::Rect(patch_coords.shift_img_1.pos.x, patch_coords.shift_img_1.pos.y, patch_coords.shift_img_1.size.x, patch_coords.shift_img_1.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_shift_1", transform_images.shift_img_1);
// 	waitKey(0);
// 	rectangle(transform_images.shift_img_2, cv::Rect(patch_coords.shift_img_2.pos.x, patch_coords.shift_img_2.pos.y, patch_coords.shift_img_2.size.x, patch_coords.shift_img_2.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_shift_2", transform_images.shift_img_2);
// 	waitKey(0);
// 	rectangle(transform_images.shift_img_3, cv::Rect(patch_coords.shift_img_3.pos.x, patch_coords.shift_img_3.pos.y, patch_coords.shift_img_3.size.x, patch_coords.shift_img_3.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_shift_3", transform_images.shift_img_3);
// 	waitKey(0);
// 	rectangle(transform_images.shift_img_4, cv::Rect(patch_coords.shift_img_4.pos.x, patch_coords.shift_img_4.pos.y, patch_coords.shift_img_4.size.x, patch_coords.shift_img_4.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_shift_4", transform_images.shift_img_4);
// 	waitKey(0);
// 	rectangle(transform_images.flip_img, cv::Rect(patch_coords.flip_img.pos.x, patch_coords.flip_img.pos.y, patch_coords.flip_img.size.x, patch_coords.flip_img.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_flip_img", transform_images.flip_img);
// 	waitKey(0);
// 	rectangle(transform_images.blur_img_1, cv::Rect(patch_coords.blur_img_1.pos.x, patch_coords.blur_img_1.pos.y, patch_coords.blur_img_1.size.x, patch_coords.blur_img_1.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_blur_img_1", transform_images.blur_img_1);
// 	waitKey(0);
// 	rectangle(transform_images.blur_img_2, cv::Rect(patch_coords.blur_img_2.pos.x, patch_coords.blur_img_2.pos.y, patch_coords.blur_img_2.size.x, patch_coords.blur_img_2.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_blur_img_2", transform_images.blur_img_2);
// 	waitKey(0);
// 	rectangle(transform_images.blur_img_3, cv::Rect(patch_coords.blur_img_3.pos.x, patch_coords.blur_img_3.pos.y, patch_coords.blur_img_3.size.x, patch_coords.blur_img_3.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_blur_img_3", transform_images.blur_img_3);
// 	waitKey(0);
// 	rectangle(transform_images.rotate_img_1, cv::Rect(patch_coords.rotate_img_1.pos.x, patch_coords.rotate_img_1.pos.y, patch_coords.rotate_img_1.size.x, patch_coords.rotate_img_1.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_rotate_img_1", transform_images.rotate_img_1);
// 	waitKey(0);
// 	rectangle(transform_images.rotate_img_2, cv::Rect(patch_coords.rotate_img_2.pos.x, patch_coords.rotate_img_2.pos.y, patch_coords.rotate_img_2.size.x, patch_coords.rotate_img_2.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_rotate_img_2", transform_images.rotate_img_2);
// 	waitKey(0);
// 	rectangle(transform_images.rotate_img_3, cv::Rect(patch_coords.rotate_img_3.pos.x, patch_coords.rotate_img_3.pos.y, patch_coords.rotate_img_3.size.x, patch_coords.rotate_img_3.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_rotate_img_3", transform_images.rotate_img_3);
// 	waitKey(0);
// 	rectangle(transform_images.rotate_img_4, cv::Rect(patch_coords.rotate_img_4.pos.x, patch_coords.rotate_img_4.pos.y, patch_coords.rotate_img_4.size.x, patch_coords.rotate_img_4.size.y), cv::Scalar(0, 255, 255), 1);
// 	imshow("transform_rotate_img_4", transform_images.rotate_img_4);
// 	waitKey(0);

// 	return 0;
// }

Result Preprocess_for_init::Init(vector<cv::Mat>& transform_imgs, vector<Target_Box>& transform_boxes, Vector& init_base_target_size, Vector& init_sample_pos, float& init_target_scale, Vector& init_target_size, Vector& init_target_pos, cv::Mat img) 
{

	string line;
	vector<string> result;
	ifstream in(filepath_);

	

	if (in)
	{
		while (getline(in, line))
		{
			line = line;

			break;
		}
	}
	in.close();
	SplitString(line, result, "	");
	int x = stoi(result[0]);
	int y = stoi(result[1]);
	int w = stoi(result[2]);
	int h = stoi(result[3]);
	// cout<< x << "+ " << y << " +" << w<<" +" << h<<endl;
	// Target_Box init_target_box = { {x, y}, { w, h} };
	// sprintf_s(filename, 10, "%04d", 1);

	cv::cvtColor(img, img, COLOR_BGR2RGB);
	//rectangle(origin_image, cv::Rect(init_target_box.pos.x, init_target_box.pos.y, init_target_box.size.x, init_target_box.size.y), cv::Scalar(0, 255, 0), 1);
	// imshow("image", origin_image);
	// waitKey(0);

	Vector target_pos = { float(y + (h - 1) / 2.0), float(x + (w - 1) / 2.0) };
	// cout<<target_pos.x<<" +++ "<<target_pos.y<<endl;
	Vector target_size = { float(h), float(w) };
	Vector image_sample_size = { 288, 288 };
	int search_area_scale = 5;
	int search_area = target_size.x * target_size.y * search_area_scale * search_area_scale;
	float target_scale = sqrt(search_area) / sqrt(image_sample_size.x * image_sample_size.y);
	Vector base_target_size = { float(target_size.x) / target_scale, float(target_size.y) / target_scale };
	int aug_expansion_factor = 2;

	Vector aug_expansion_size = { image_sample_size.x * aug_expansion_factor, image_sample_size.y * aug_expansion_factor };
	Vector offset = { float(int(aug_expansion_size.x - image_sample_size.x) % 2), float(int(aug_expansion_size.y - image_sample_size.y) % 2) };
	aug_expansion_size.x += offset.x;
	aug_expansion_size.y += offset.y;

	Vector sample_input_size = { aug_expansion_size.x * target_scale, aug_expansion_size.y * target_scale };
	Vector sample_pos = { ceil(target_pos.x), ceil(target_pos.y) };
	Target_Box init_box = get_iou_box(target_pos, target_size, sample_pos, target_scale);
	Box sample_coords;
	Mat sample_img = sample_patch(img, sample_pos, sample_input_size, aug_expansion_size, &sample_coords);
	transform_image(sample_img, init_box, transform_imgs, transform_boxes);

	init_target_size.x = target_size.x;
	init_target_size.y = target_size.y;
	init_base_target_size.x = base_target_size.x;
	init_base_target_size.y = base_target_size.y;
	init_sample_pos.x = sample_pos.x;
	init_sample_pos.y = sample_pos.y;
	init_target_scale = target_scale;
	init_target_pos.x = target_pos.x;
	init_target_pos.y = target_pos.y;

	//imshow("transform_imgs_flip_img", transform_imgs.flip_img);
	//waitKey(0);
	//imshow("transform_imgs_blur_img_1", transform_imgs.blur_img_1);
	//waitKey(0);

	//test_transform(transform_imgs, patch_coords);

	return SUCCESS;

}


// int track(Vector base_target_size, string filepath, string imgpath, Vector sample_pos, float target_scale)
// {
// 	string line;

// 	ifstream file(filepath);
// 	int i = 1;
// 	bool flag = false;
// 	char filename[10];
// 	Vector target_pos;
// 	Vector target_size;
// 	string image_full_path;
// 	Mat tracking_image;
// 	Vector new_sample_size;
// 	Mat sample_img;
// 	Box sample_coords;
// 	int new_target_area;

// 	cout << "start tracking!" << endl;

// 	if (file)
// 	{
// 		while (getline(file, line))
// 		{
// 			if (flag == true)
// 			{
// 				flag = false;
// 				continue;
// 			}
// 			i++;
// 			cout << line << endl;
// 			sprintf_s(filename, 10, "%04d", i);
// 			cout << filename << endl;
// 			image_full_path = imgpath + filename + ".jpg";
// 			cout << image_full_path << endl;
// 			tracking_image = imread(image_full_path);
// 			target_pos.x = sample_pos.x;
// 			target_pos.y = sample_pos.y;
// 			new_sample_size.x = 288 * target_scale;
// 			new_sample_size.y = 288 * target_scale;
// 			imshow("tracking_image", tracking_image);
// 			waitKey(0);
// 			sample_img = sample_patch(tracking_image, target_pos, new_sample_size, { 288, 288 }, &sample_coords);

// 			vector<string> result;
// 		//	line = line;
// 			SplitString(line, result, "	");
// 			int x = stoi(result[0]);
// 			int y = stoi(result[1]);
// 			int w = stoi(result[2]);
// 			int h = stoi(result[3]);

// 			target_pos.x = (y + h / 2);
// 			target_pos.y = (x + w / 2);
// 			target_size.x = h;
// 			target_size.y = w;

// 			new_target_area = target_size.x * target_size.y;
// 			target_scale = sqrt(new_target_area / (base_target_size.x * base_target_size.y));
// 			sample_pos.x = target_pos.x;
// 			sample_pos.y = target_pos.y;
// 			imshow("tracking_sample_image", sample_img);
// 			waitKey(0);
// 		}
// 	}

// 	return 0;
// }

// int main()
// {
// 	Vector init_base_target_size;
// 	Vector init_sample_pos;
// 	float init_target_scale;
// 	string imgpath = "E:/WZM-DESKTOP/Object-Tracking/codes/pytracking/pytracking/OTB/test_video/full_12/img/";
// 	string filepath = "E:/WZM-DESKTOP/Object-Tracking/codes/pytracking/pytracking/OTB/test_video/full_12/groundtruth_rect.txt";

// 	init(&init_base_target_size, filepath, imgpath, &init_sample_pos, &init_target_scale);

// 	track(init_base_target_size, filepath, imgpath, init_sample_pos, init_target_scale);

// 	return 0;
// }